Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[make:user] implement getUserIdentifier if required #862

Merged
merged 1 commit into from
Apr 24, 2021

Conversation

jrushlow
Copy link
Collaborator

@jrushlow jrushlow commented Apr 19, 2021

handle getUsername() -> getUserIdentifier() in Symfony 5.3 symfony/symfony#40403

Copy link
Member

@weaverryan weaverryan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minus the tests and one comment, this is looking very nice 👍

src/Security/UserClassBuilder.php Show resolved Hide resolved
@jrushlow jrushlow force-pushed the feature/make-user-identifier branch 2 times, most recently from f5f7198 to 8a75a11 Compare April 21, 2021 17:27
@jrushlow jrushlow marked this pull request as ready for review April 21, 2021 17:27
@@ -3,7 +3,7 @@
namespace <?= $namespace; ?>;

use Symfony\Component\Security\Core\Exception\UnsupportedUserException;
use Symfony\Component\Security\Core\Exception\UsernameNotFoundException;
use Symfony\Component\Security\Core\Exception\<?= $uses_user_identifier ? 'UserNotFoundException' : 'UsernameNotFoundException' ?>;
<?= ($password_upgrader = interface_exists('Symfony\Component\Security\Core\User\PasswordUpgraderInterface')) ? "use Symfony\Component\Security\Core\User\PasswordUpgraderInterface;\n" : '' ?>
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\User\UserProviderInterface;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We really need to, at some point, write a util class where we plug all the use statements into... then we just dump echo $useStatements->render() in the template :p

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No kidding.. use statements are getting harder and harder to manage lately.. have a solution on the todo list ;)

$getterIdentifierName = 'getUsername';

// Check if we're using Symfony 5.3+ - UserInterface::getUsername() was replaced with UserInterface::getUserIdentifier()
if (class_exists(InMemoryUser::class)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class DOES only exist on 5.3. But why did you choose this class specifically? Could we use something more direct like method_exists(Symfony\Component\Security\Core\User\User::class, 'getUserIdentifier')?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

@weaverryan weaverryan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one tiny comment!

@weaverryan
Copy link
Member

Thanks Jesse!

@weaverryan weaverryan merged commit 4b94fc1 into symfony:main Apr 24, 2021
@jrushlow jrushlow deleted the feature/make-user-identifier branch April 25, 2021 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants